package com.Nineza.otherstuph;

import java.io.File;
import java.util.HashMap;

import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.Server;
import org.bukkit.World;
import org.bukkit.event.Event.Priority;
import org.bukkit.event.Event;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.PluginLoader;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.plugin.PluginManager;

/**
* Plugin for Bukkit
*
* @author Nineza
*/
public class OtherStuph extends JavaPlugin {
    private final String forumlink = "http://forum.ryanteck.org.uk/";
	private final OSPlayerListener playerListener = new OSPlayerListener(this);
    private final OSBlockListener blockListener = new OSBlockListener(this);
    private final HashMap<Player, Boolean> debugees = new HashMap<Player, Boolean>();

    // NOTE: There should be no need to define a constructor any more for more info on moving from
    // the old constructor see:
    // http://forums.bukkit.org/threads/too-long-constructor.5032/
    
    @Override
    public void onDisable() {
        // TODO: Place any custom disable code here

        // NOTE: All registered events are automatically unregistered when a plugin is disabled

        // EXAMPLE: Custom code, here we just output some info so we can check all is well
        System.out.println("Goodbye world!");
    }

    @Override
    public void onEnable() {
        // TODO: Place any custom enable code here including the registration of any events

        // Register our events
        PluginManager pm = getServer().getPluginManager();
        /*pm.registerEvent(Event.Type.PLAYER_JOIN, playerListener, Priority.Normal, this);
        pm.registerEvent(Event.Type.PLAYER_QUIT, playerListener, Priority.Normal, this);
        pm.registerEvent(Event.Type.PLAYER_MOVE, playerListener, Priority.Normal, this);
        pm.registerEvent(Event.Type.BLOCK_PHYSICS, blockListener, Priority.Normal, this);
        pm.registerEvent(Event.Type.BLOCK_CANBUILD, blockListener, Priority.Normal, this);*/

        // EXAMPLE: Custom code, here we just output some info so we can check all is well
        PluginDescriptionFile pdfFile = this.getDescription();
        System.out.println( pdfFile.getName() + " version " + pdfFile.getVersion() + " is enabled!" );
    }

    public boolean isDebugging(final Player player) {
        if (debugees.containsKey(player)) {
            return debugees.get(player);
        } else {
            return false;
        }
    }

    public void setDebugging(final Player player, final boolean value) {
        debugees.put(player, value);
    }
    @Override
    public boolean onCommand(CommandSender sender, Command command, String commandLabel, String[] args)
    {
    	String[] split = args;
    	String commandName = command.getName().toLowerCase();
    	
    	if(sender instanceof Player)
    	{
    		Player player = (Player) sender;
                
    		if (commandName.equals("ostest")) {
    			player.sendMessage("Hi there, " + player.getDisplayName() + "! =D");
    			return true;
    		} else if (commandName.equals("gettime")) {
    			player.sendMessage("The time is " + player.getWorld().getTime() % 24000 + "!");
    			return true;
    		} else if (commandName.equals("forum")) {
    			player.sendMessage("The forums are at: " + this.forumlink + "!");
    			return true;
    		}
    	}
    	return false;
    }
}